package com.garen.projects.demo.provider.handler;

import com.garen.projects.demo.provider.model.Response;
import com.garen.projects.demo.provider.model.user.UserQuery;
import com.garen.projects.demo.provider.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/{id}")
    public Response<UserQuery> query(@PathVariable("id") Long id) {
        UserQuery userQuery = userService.query(id);
        if (userQuery == null) {
            return new Response<UserQuery>("9999", "查询失败！" + serverPort);
        } else {
            return new Response<UserQuery>("9999", "查询成功！" + serverPort, userQuery);
        }
    }
}
